package org.qiyu.live.im.core.server.common;

import io.netty.channel.ChannelHandlerContext;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: ChannelHandlerContextCache
 * @Description: TODO
 * @Author zhangguangyan
 * @Date 2023/09/08/ 21:18:05
 * @Version 1.0
 */
public class ChannelHandlerContextCache {
    /**
     * @Description 当前im服务启动的时候,对外暴露的ip和端口
     * @Author zhangguangyan
     * @Date 2023-10-01 08:26:11
     */
    private static String SERVER_IP_ADDRESS = "";

    public static String getServerIpAddress() {
        return SERVER_IP_ADDRESS;
    }

    public static void setServerIpAddress(String serverIpAddress) {
        SERVER_IP_ADDRESS = serverIpAddress;
    }

    private static Map<Long, ChannelHandlerContext> channelHandlerContextMap = new HashMap<>();

    public static ChannelHandlerContext get(Long userId) {
        return channelHandlerContextMap.get(userId);
    }

    /**
     * @param channelHandlerContext
     * @Params @param userId
     * @Return
     * @Description 通过userId获取channelHandlerContext
     * @Author zhangguangyan
     * @Date 2023-09-08 21:20:59
     */
    public static void put(Long userId, ChannelHandlerContext channelHandlerContext) {
        channelHandlerContextMap.put(userId, channelHandlerContext);
    }

    /**
     * @Params @param userId
     * @Return
     * @Description 通过userId移除channelHandlerContext
     * @Author zhangguangyan
     * @Date 2023-09-08 21:21:36
     */

    public static void remove(Long userId) {
        channelHandlerContextMap.remove(userId);
    }
}
